<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>高度不固定的盒子 垂直居中</title>
    <style type="text/css">
        * { margin: 0; padding: 0; }
        /*方法1*/
        .box { width: 100%; height: 400px; background: pink; text-align: center; font-size: 0; }
        .vertical-align-span { width: 1px; display: inline-block; height: 100%; vertical-align:middle; background: blue; margin-left:-1px; }
        .box1 { width: 100px; background: grey; display: inline-block; vertical-align: middle; font-size: 16px; }
        .box2 { width: 100px; background: goldenrod; display: inline-block; vertical-align: middle; font-size: 16px; }

        /*方法2*/
        #vc{display:table; background:pink; width:500px; height:200px; overflow:hidden; margin:0 auto; _position:relative;}
        #vci{vertical-align:middle; display:table-cell; _position:absolute; _top:50%;}
        #content{color:#fff; border:1px solid #fff; _position:relative; _top:-50%;}
    </style>
</head>
<body>
<div class="box">
    <span class="vertical-align-span"></span>
    <div class="box1">这是第一个盒子，只是有些内容，没有固定的高</div>
    <div class="box2">盒子2，只是有些内容，没有固定的高</div>
</div>

<br>
<br>
<br>
<div id="vc">
    <div id="vci">
        <div id="content">我们垂直居中了</div>
    </div>
</div>
</body>
</html>